﻿/* 项目名称： WindowCollection.cs
 * 命名空间： Vampirewal.Core.SimpleMVVM
 * 类 名 称: WindowCollection
 * 作   者 : 杨程
 * 概   述 :
 * 创建时间 : 2021/2/20 18:46:12
 * 更新时间 : 2021/2/20 18:46:12
 * CLR版本 : 4.0.30319.42000
 * ******************************************************
 * Copyright@Administrator 2021 .All rights reserved.
 * ******************************************************
 */

namespace Vampirewal.Core.SimpleMVVM;

/// <summary>
/// Windows窗体
/// </summary>
public interface IWindows
{
    event EventHandler Closed;

    bool Activate();

    void Close();

    void Hide();

    void Show();

    bool? ShowDialog();

    bool Topmost { get; set; }

    bool ShowInTaskbar { get; set; }

    string Name { get; set; }

    object DataContext { get; set; }

    object Content { get; set; }

    /// <summary>
    /// ViewModel
    /// </summary>
    ViewModelBase DataSource { get; set; }

    /// <summary>
    /// 对应ViewModelKey
    /// </summary>
    string ViewModelKey { get; }

    /// <summary>
    /// 窗体ID
    /// </summary>
    Guid ViewId { get; set; }
}

public interface IDialogWindow : IWindows
{
    /// <summary>
    /// 设置
    /// </summary>
    /// <param name="setting"></param>
    void Setting(DialogWindowSetting setting);

    ICommand CloseDialogWindowCallBackCommand { get; set; }
}

public interface IPopupWindow : IWindows
{
    /// <summary>
    /// 设置
    /// </summary>
    /// <param name="setting"></param>
    void Setting(PopupWindowSetting setting);
}

public interface INotifyWindow : IWindows
{
    /// <summary>
    /// 设置
    /// </summary>
    /// <param name="setting"></param>
    void Setting(NotifyWindowSetting setting);
}

/// <summary>
/// 文件夹选择器窗体
/// </summary>
public interface IFolderPickerWindow : IWindows
{
    /// <summary>
    /// 选择的文件夹路径
    /// </summary>
    string SelectedPath { get; }

    /// <summary>
    /// 读取文件夹
    /// </summary>
    /// <param name="defaultPath">默认路径</param>
    void LoadDirectory(string defaultPath = "");
}

public interface IUcViewBase
{
    double MinWidth { get; set; }
    double MaxWidth { get; set; }
    double MinHeight { get; set; }
    double MaxHeight { get; set; }
    double Height { get; set; }
    double Width { get; set; }
    double ActualWidth { get; }
    object DataContext { get; set; }

    /// <summary>
    /// 对应ViewModelKey
    /// </summary>
    string ViewModelKey { get; }
    /// <summary>
    /// ViewModel
    /// </summary>
    ViewModelBase DataSource { get; set; }

    /// <summary>
    /// 窗体ID
    /// </summary>
    Guid ViewId { get; }
}

/// <summary>
/// Mdi容器内窗体基类
/// </summary>
public interface IMdiChildViewBase: IUcViewBase
{
    /// <summary>
    /// 图标路径
    /// </summary>
    string IconPath { get; set; }

    /// <summary>
    /// 应用名称
    /// </summary>
    string Title { get; set; }

    /// <summary>
    /// 设置
    /// </summary>
    /// <param name="setting"></param>
    void Setting(MdiChildViewSetting setting);
}

/// <summary>
/// 窗口集合
/// </summary>
public class WindowCollection : List<IWindows>
{
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="window"></param>
    public new void Add(IWindows window)
    {
        window.Closed += Window_Closed;
        window.Activate();
        base.Add(window);
    }

    private void Window_Closed(object sender, EventArgs e)
    {
        base.Remove((IWindows)sender);
    }

    public IWindows this[string WindowName]
    {
        get
        {
            if (!string.IsNullOrEmpty(WindowName))
            {
                return this.FirstOrDefault(f => f.Name == WindowName);
            }
            else
            {
                return null;
            }
        }
    }


    public IWindows this[Guid viewId]
    {
        get
        {
            var view= this.FirstOrDefault(f=>f.ViewId == viewId);

            return view;
        }
    }
}